using System;
using System.Collections.Generic;
using System.Linq;
namespace TemplateWeb.Controllers
{
	#region using
	using System.Web.Mvc;
	using TemplateWeb.Models.ViewModels;
	using TemplateWeb.Models;
	using TemplateWeb.Models.Repositories;
	using TemplateWeb.Helpers;
	using System.Web.Security;
	#endregion
	public partial class AdminController: BaseController
	{
		public ActionResult SelectLoaiTinTuc()
		{
			var data = new DataTransferViewModel
			{
				EnumViewModelType = EnumViewModel.ADMIN_LOAITINTUC
			};
			return View(CreateViewModel(data));
		}



		public ActionResult DeleteLoaiTinTuc(int id, int page = 1)
		{
			var result = _repLoaiTinTuc.Delete(id);
			var data = new DataTransferViewModel
			{
				InfoText = result ? "Item has been deleted" : "Cannot delete item!",
				EnumViewModelType = EnumViewModel.ADMIN_LOAITINTUC,
				CurrentPage = page
			};
			return View("SelectLoaiTinTuc", CreateViewModel(data));
		}

		public ActionResult EditLoaiTinTuc(int page, int id)
		{
			var data = new DataTransferViewModel
			{
				EnumViewModelType = EnumViewModel.ADMIN_LOAITINTUC,
				CurrentPage = page,
				IntID = id
			};
			return PartialView("Templates/TH_EditLoaiTinTuc", CreateViewModel(data));
		}

		public ActionResult CancelEditingLoaiTinTuc(int page)
		{
			var data = new DataTransferViewModel
			{
				EnumViewModelType = EnumViewModel.ADMIN_LOAITINTUC,
				CurrentPage = page
			};
			return PartialView("Templates/TH_ListLoaiTinTuc", CreateViewModel(data));
		}

		[ValidateInput(false)]
		[AcceptVerbs(HttpVerbs.Post)]
		public ActionResult UpdateLoaiTinTuc(FormCollection forms)
		{
			string id = forms.GetValues("LoaiTinTuc_ID")[0];
			string tenloaitintuc = forms.GetValues("LoaiTinTuc_TenLoaiTinTuc")[0];
			var loaitintuc = _repLoaiTinTuc.SelectByID(int.Parse(id));
			loaitintuc.TenLoaiTinTuc = tenloaitintuc;
			var result = _repLoaiTinTuc.Save();
			var data = new DataTransferViewModel
			{
				EnumViewModelType = EnumViewModel.ADMIN_LOAITINTUC,
			};
			return View("SelectLoaiTinTuc", CreateViewModel(data));
		}


		[ValidateInput(false)]
		[AcceptVerbs(HttpVerbs.Post)]
		public ActionResult InsertLoaiTinTuc(FormCollection forms)
		{
			string tenloaitintuc = forms.GetValues("LoaiTinTuc_TenLoaiTinTuc")[0];
			var newItem = new LoaiTinTuc
			{
				TenLoaiTinTuc = tenloaitintuc
			};
			var result = _repLoaiTinTuc.Insert(newItem);
			var data = new DataTransferViewModel
			{
				EnumViewModelType = EnumViewModel.ADMIN_LOAITINTUC,
				InfoText = result ? "New item has been added" : "Cannot insert new item"
			};
			return View("SelectLoaiTinTuc", CreateViewModel(data));
		}


	}
}